import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import BMap

df=pd.read_excel('2022年北京市工作日早高峰进站量前20的地铁站.xlsx')
data=df[['地铁站','进站量（千人次）']].values.tolist()
bMap=BMap(init_opts=opts.InitOpts(
    width='1000px',height='800px',page_title='地理热力图'))
for (name, longitude, latitude) in zip(df['地铁站'], df['经度'], df['纬度']):
    bMap.add_coordinate(name, longitude,latitude)
bMap.add_schema(baidu_ak='PmSUNz1vB2wZMLui6vGozZkMKQb1Q5AC',center=[116.404699,39.899689], zoom=11)
bMap.add(series_name='', data_pair=data, type_='heatmap')
bMap.add(series_name='', data_pair=data,
         type_='scatter', symbol_size=0,
         label_opts=opts.LabelOpts(
             position='top',distance=10,color='red',
             font_style='italic',font_weight='bold',
             font_size=15, formatter='{b}')
         )

bMap.set_global_opts(
    title_opts=opts.TitleOpts(
        title='2022年北京市工作日早高峰进站量前20的地铁站进站量地理热力图',
        pos_left='center'),
    legend_opts=opts.LegendOpts(is_show=False),
    visualmap_opts=opts.VisualMapOpts(
        max_=23, min_=8, pos_top='75%',
        range_color=['green','yellow','red']
    )
)
bMap.render('例9-2.html')